<?php

/**
 * This file is part of the Codizer package.
 *
 * For the full copyright and license information, please view the LICENSE
 * file that was distributed with this source code.
 *
 * @copyright   Copyright (c) 2010 Advisa (http://www.advisa.fr)
 * @author      Codizer Core Team <team@codizer.org>
 * @package     Codizer
 */

class f_form_checkers_checkRegex extends f_form_Checker
{
	public function check()
	{
		$value = $this->getValue();
		$regex = $this->getAttribute("regex");
		
		if(is_null($regex))
		{
			throw new Exception("The regular expression is missing");
		}
		
		if(!empty($value) && !preg_match($regex, $value))
		{
			return $this->getErrorMessage();
		}
		
		return true;
	}
}